{% if Count > 0 %}
<div class="page-body">
  <div class="container-xl">
    <div class="row row-cards">
      {% for Media in Medias %}
      <div class="col-12 col-xl-6">
        {% if OperType == 'search' %}
        <a class="card card-link card-link-pop rounded-3" href="javascript:medialist_search('{{ Media.tmdb_id }}', '{{ Media.title }}', '{{ Media.type.value }}')" style="padding:0px 0px; overflow:hidden">
        {% else %}
        <div class="card card-link-pop rounded-3" style="padding:0px 0px; overflow:hidden">
        {% endif %}
          <div class="ribbon ribbon-top ribbon-bookmark bg-purple">{{ Media.vote_average }}</div>
          <div class="row" style="max-height:240px; overflow:hidden">
            <div class="col-4 col-md-3 col-lg-4 col-xl-3" style="padding:0px 0px">
              <span class="badge badge-pill {% if Media.type.value == '电影' %}bg-green{% else %}bg-blue{% endif %}" style="position:absolute;top:10px;left:10px;">{{Media.type.value}}</span>
              <img src="{% if Media.poster_path %}{{ Media.poster_path }}{% else %}../static/img/no-image.png{% endif %}" class="w-100 h-100 object-cover">
            </div>
            <div class="col">
              <div class="card-body">
                <h2>
                  {{ Media.title }} <span class="text-muted">({{ Media.year }})</span>
                </h2>
                <div class="badge badge-outline text-orange mb-1">{% if Media.tmdb_id is string and Media.tmdb_id.startswith('DB') %}{{ Media.tmdb_id[3:] }}{% else %}{{ Media.tmdb_id }}{% endif %}</div>
                <div class="text-muted mb-3 pb-3">
                  {{ Media.overview|truncate(100, True) }}
                </div>
              </div>
            </div>
          </div>
          {% if OperType != 'search' %}
          <div class="d-flex">
            <a href="javascript:add_medialist_rss_media('{{ Media.title }}','{{ Media.year }}','{{ Media.type.value }}','{{ Media.tmdb_id }}')" class="card-btn">
              <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-rss me-2 text-muted" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                 <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                 <circle cx="5" cy="19" r="1"></circle>
                 <path d="M4 4a16 16 0 0 1 16 16"></path>
                 <path d="M4 11a9 9 0 0 1 9 9"></path>
              </svg>
              订阅
            </a>
            <a href="javascript:medialist_search('{{ Media.tmdb_id }}', '{{ Media.title }}', '{{ Media.type.value }}')" class="card-btn">
              <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-search me-2 text-muted" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                 <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                 <circle cx="10" cy="10" r="7"></circle>
                 <line x1="21" y1="21" x2="15" y2="15"></line>
              </svg>
              搜索
            </a>
          </div>
          {% endif %}
        {% if OperType != 'search' %}
        </div>
        {% else %}
        </a>
        {% endif %}
      </div>
      {% endfor %}
    </div>
  </div>
</div>
{% else %}
<div class="page-body">
  <div class="container-xl d-flex flex-column justify-content-center">
    <div class="empty">
      <div class="empty-img"><img src="./static/img/posting_photo.svg" height="128" alt="">
      </div>
      <p class="empty-title" id="search_tip_title">未找到</p>
      <p class="empty-subtitle text-muted" id="search_tip_text">
        没有找到任何电影、电视剧叫这个名字："{{ SearchWord }}"
      </p>
    </div>
  </div>
</div>
{% endif %}
<script type="text/javascript">
  //搜索
  function medialist_search(tmdbid, title, type){
    var param = { "tmdbid": tmdbid, "search_word": title, "media_type": type };
    show_wait_process();
    ajax_post("search", param, function (ret) {
      hide_wait_process();
      navmenu('search?s=' + title)
    });
  }
  //新增订阅
  function add_medialist_rss_media(name, year, type, tmdbid){
    if(type == "电影"){
      type = "MOV";
    }else{
      type = "TV";
    }
    if(tmdbid && tmdbid.startsWith("DB:")){
      var doubanid = tmdbid.replace("DB:", "");
      tmdbid = "";
    }else{
      var doubanid = "";
    }
    var data = { "name": name, "type": type, "year": year, "doubanid": doubanid, "tmdbid": tmdbid};
    show_wait_process();
    ajax_post("add_rss_media", data, function(ret){
      hide_wait_process();
      if(ret.code==0){
        show_success_modal(ret.name + " 添加RSS订阅成功！");
      }else{
        show_fail_modal(ret.name + " 添加RSS订阅失败："+ ret.msg +"！");
      }
    });
  }
</script>
